//
// tbllim.cpp
//

#include "tbllim.h"
#include "crbet.h"

CTableLimits::CTableLimits()
{
	m_minPassSet		= -1;
	m_maxPassSet		= -1;
	m_minOddsSet		= -1;
	m_maxOddsSet		= -1;
	m_minPlaceSet		= -1;
	m_maxPlaceSet		= -1;
	m_minHardPropsSet	= -1;
	m_maxHardPropsSet	= -1;
	m_minFieldBigSet	= -1;
	m_maxFieldBigSet	= -1;

	m_minTable			= -1;
	m_maxTable			= -1;
	m_betOdds			= -1;
	m_field12Odds		= -1;
	m_compFactor		= -1;

    m_nLargestBet       = -1;
}

CTableLimits::CTableLimits(int32 minPassSet, int32 maxPassSet, int32 minOddsSet, int32 maxOddsSet,
					 int32 minPlaceSet, int32 maxPlaceSet, int32 minHardPropsSet, int32 maxHardPropsSet,
					 int32 minFieldBigSet, int32 maxFieldBigSet, int32 minTable, int32 maxTable,
					 int32 betOdds, int32 field12Odds, int32 compFactor)
{
	m_minPassSet		= minPassSet;
	m_maxPassSet		= maxPassSet;
	m_minOddsSet		= minOddsSet;
	m_maxOddsSet		= maxOddsSet;
	m_minPlaceSet		= minPlaceSet;
	m_maxPlaceSet		= maxPlaceSet;
	m_minHardPropsSet	= minHardPropsSet;
	m_maxHardPropsSet	= maxHardPropsSet;
	m_minFieldBigSet	= minFieldBigSet;
	m_maxFieldBigSet	= maxFieldBigSet;

	m_minTable			= minTable;
	m_maxTable			= maxTable;
	m_betOdds			= betOdds;
	m_field12Odds		= field12Odds;
	m_compFactor		= compFactor;

    // kharmon.  01-03-06.  #7916.  Get the largest single bet value allowed by the table limit settings.
    m_nLargestBet = MAX(m_maxPassSet, MAX(m_maxOddsSet, MAX(m_maxPlaceSet, MAX(m_maxFieldBigSet,m_maxHardPropsSet))));
}


CTableLimits::~CTableLimits()
{
	m_minPassSet		= -1;
	m_maxPassSet		= -1;
	m_minOddsSet		= -1;
	m_maxOddsSet		= -1;
	m_minPlaceSet		= -1;
	m_maxPlaceSet		= -1;
	m_minHardPropsSet	= -1;
	m_maxHardPropsSet	= -1;
	m_minFieldBigSet	= -1;
	m_maxFieldBigSet	= -1;

	m_minTable			= -1;
	m_maxTable			= -1;
	m_betOdds			= -1;
	m_field12Odds		= -1;
	m_compFactor		= -1;

    m_nLargestBet       = -1;
}

void
CTableLimits::set(int32 minPassSet, int32 maxPassSet, int32 minOddsSet, int32 maxOddsSet,
					 int32 minPlaceSet, int32 maxPlaceSet, int32 minHardPropsSet, int32 maxHardPropsSet,
					 int32 minFieldBigSet, int32 maxFieldBigSet, int32 minTable, int32 maxTable,
					 int32 betOdds, int32 field12Odds, int32 compFactor)
{
	m_minPassSet		= minPassSet;
	m_maxPassSet		= maxPassSet;
	m_minOddsSet		= minOddsSet;
	m_maxOddsSet		= maxOddsSet;
	m_minPlaceSet		= minPlaceSet;
	m_maxPlaceSet		= maxPlaceSet;
	m_minHardPropsSet	= minHardPropsSet;
	m_maxHardPropsSet	= maxHardPropsSet;
	m_minFieldBigSet	= minFieldBigSet;
	m_maxFieldBigSet	= maxFieldBigSet;

	m_minTable			= minTable;
	m_maxTable			= maxTable;
	m_betOdds			= betOdds;
	m_field12Odds		= field12Odds;
	m_compFactor		= compFactor;

    // kharmon.  01-03-06.  #7916.  Get the largest single bet value allowed by the table limit settings.
    m_nLargestBet = MAX(m_maxPassSet, MAX(m_maxOddsSet, MAX(m_maxPlaceSet, MAX(m_maxFieldBigSet,m_maxHardPropsSet))));
}

void
CTableLimits::initialize()
{
	m_minPassSet		= -1;
	m_maxPassSet		= -1;
	m_minOddsSet		= -1;
	m_maxOddsSet		= -1;
	m_minPlaceSet		= -1;
	m_maxPlaceSet		= -1;
	m_minHardPropsSet	= -1;
	m_maxHardPropsSet	= -1;
	m_minFieldBigSet	= -1;
	m_maxFieldBigSet	= -1;

	m_minTable			= -1;
	m_maxTable			= -1;
	m_betOdds			= -1;
	m_field12Odds		= -1;
	m_compFactor		= -1;

    m_nLargestBet       = -1;
}

int32
CTableLimits::getBetMin(uint8 betid)
{
	switch(betid)
	{
		case CrapsBet::Pass:
		case CrapsBet::DontPass:
		case CrapsBet::Come:
		case CrapsBet::Come4:
		case CrapsBet::Come5:
		case CrapsBet::Come6:
		case CrapsBet::Come8:
		case CrapsBet::Come9:
		case CrapsBet::Come10:
		case CrapsBet::DontCome:
		case CrapsBet::DontCome4:
		case CrapsBet::DontCome5:
		case CrapsBet::DontCome6:
		case CrapsBet::DontCome8:
		case CrapsBet::DontCome9:
		case CrapsBet::DontCome10:

			return m_minPassSet;
			break;

		case CrapsBet::PassOdds:
		case CrapsBet::DontPassOdds:
		case CrapsBet::Come4Odds:
		case CrapsBet::Come5Odds:
		case CrapsBet::Come6Odds:
		case CrapsBet::Come8Odds:
		case CrapsBet::Come9Odds:
		case CrapsBet::Come10Odds:
		case CrapsBet::DontCome4Odds:
		case CrapsBet::DontCome5Odds:
		case CrapsBet::DontCome6Odds:
		case CrapsBet::DontCome8Odds:
		case CrapsBet::DontCome9Odds:
		case CrapsBet::DontCome10Odds:

			return m_minOddsSet;
			break;

		case CrapsBet::Lay4:
		case CrapsBet::Lay5:
		case CrapsBet::Lay6:
		case CrapsBet::Lay8:
		case CrapsBet::Lay9:
		case CrapsBet::Lay10:
		case CrapsBet::Buy4:
		case CrapsBet::Buy5:
		case CrapsBet::Buy6:
		case CrapsBet::Buy8:
		case CrapsBet::Buy9:
		case CrapsBet::Buy10:
		case CrapsBet::Place4:
		case CrapsBet::Place5:
		case CrapsBet::Place6:
		case CrapsBet::Place8:
		case CrapsBet::Place9:
		case CrapsBet::Place10:
		case CrapsBet::Place4Lose:
		case CrapsBet::Place5Lose:
		case CrapsBet::Place6Lose:
		case CrapsBet::Place8Lose:
		case CrapsBet::Place9Lose:
		case CrapsBet::Place10Lose:

			return m_minPlaceSet;
			break;

		case CrapsBet::CircleAnyCraps:
		case CrapsBet::YoEleven:
		case CrapsBet::Seven:
		case CrapsBet::AnyCraps:
		case CrapsBet::Hard4:
		case CrapsBet::Hard6:
		case CrapsBet::Hard10:
		case CrapsBet::Hard8:
		case CrapsBet::Craps3:
		case CrapsBet::SnakeEyes:
		case CrapsBet::Eleven:
		case CrapsBet::BoxCars:

			return m_minHardPropsSet;
			break;
			
		case CrapsBet::Field:
		case CrapsBet::Big6:
		case CrapsBet::Big8:

			return m_minFieldBigSet;
			break;

		// should never get here
		default:
			return -1;
	}
}

int32
CTableLimits::getBetMax(uint8 betid)
{
	switch(betid)
	{
		case CrapsBet::Pass:
		case CrapsBet::DontPass:
		case CrapsBet::Come:
		case CrapsBet::Come4:
		case CrapsBet::Come5:
		case CrapsBet::Come6:
		case CrapsBet::Come8:
		case CrapsBet::Come9:
		case CrapsBet::Come10:
		case CrapsBet::DontCome:
		case CrapsBet::DontCome4:
		case CrapsBet::DontCome5:
		case CrapsBet::DontCome6:
		case CrapsBet::DontCome8:
		case CrapsBet::DontCome9:
		case CrapsBet::DontCome10:

			return m_maxPassSet;
			break;

		case CrapsBet::PassOdds:
		case CrapsBet::Come4Odds:
		case CrapsBet::Come5Odds:
		case CrapsBet::Come6Odds:
		case CrapsBet::Come8Odds:
		case CrapsBet::Come9Odds:
		case CrapsBet::Come10Odds:
			return m_maxOddsSet;
			break;

		case CrapsBet::Lay4:
		case CrapsBet::Lay5:
		case CrapsBet::Lay6:
		case CrapsBet::Lay8:
		case CrapsBet::Lay9:
		case CrapsBet::Lay10:
		case CrapsBet::Buy4:
		case CrapsBet::Buy5:
		case CrapsBet::Buy6:
		case CrapsBet::Buy8:
		case CrapsBet::Buy9:
		case CrapsBet::Buy10:
		case CrapsBet::Place4:
		case CrapsBet::Place5:
		case CrapsBet::Place6:
		case CrapsBet::Place8:
		case CrapsBet::Place9:
		case CrapsBet::Place10:
		case CrapsBet::Place4Lose:
		case CrapsBet::Place5Lose:
		case CrapsBet::Place6Lose:
		case CrapsBet::Place8Lose:
		case CrapsBet::Place9Lose:
		case CrapsBet::Place10Lose:

			return m_maxPlaceSet;
			break;

		case CrapsBet::CircleAnyCraps:
		case CrapsBet::YoEleven:
		case CrapsBet::Seven:
		case CrapsBet::AnyCraps:
		case CrapsBet::Hard4:
		case CrapsBet::Hard6:
		case CrapsBet::Hard10:
		case CrapsBet::Hard8:
		case CrapsBet::Craps3:
		case CrapsBet::SnakeEyes:
		case CrapsBet::Eleven:
		case CrapsBet::BoxCars:

			return m_maxHardPropsSet;
			break;
			
		case CrapsBet::Field:
		case CrapsBet::Big6:
		case CrapsBet::Big8:

			return m_maxFieldBigSet;
			break;

		// bwardlow 5-May-2006 #10761
		// The maximum bet amount on Don't Pass Odds and Don't Come Odds is a
		// function of the point and the table odds, but will not exceed twice
		// the bet placed multiplied times the table odds.
		case CrapsBet::DontPassOdds:
		case CrapsBet::DontCome4Odds:
		case CrapsBet::DontCome5Odds:
		case CrapsBet::DontCome6Odds:
		case CrapsBet::DontCome8Odds:
		case CrapsBet::DontCome9Odds:
		case CrapsBet::DontCome10Odds:
			return m_betOdds * 2 * m_maxPassSet;
			break;

		// should never get here
		default:
			return -1;
	}

}


CTableLimits&
CTableLimits::operator=(const CTableLimits &limits)
{
	m_minPassSet		= limits.m_minPassSet;
	m_maxPassSet		= limits.m_maxPassSet;
	m_minOddsSet		= limits.m_minOddsSet;
	m_maxOddsSet		= limits.m_maxOddsSet;
	m_minPlaceSet		= limits.m_minPlaceSet;
	m_maxPlaceSet		= limits.m_maxPlaceSet;
	m_minHardPropsSet	= limits.m_minHardPropsSet;
	m_maxHardPropsSet	= limits.m_maxHardPropsSet;
	m_minFieldBigSet	= limits.m_minFieldBigSet;
	m_maxFieldBigSet	= limits.m_maxFieldBigSet;

	m_minTable			= limits.m_minTable;
	m_maxTable			= limits.m_maxTable;
	m_betOdds			= limits.m_betOdds;
	m_field12Odds		= limits.m_field12Odds;
	m_compFactor		= limits.m_compFactor;

    m_nLargestBet       = limits.m_nLargestBet;
	
	return *this;
}

bool8
CTableLimits::operator == (const CTableLimits &limits)
{
	// Note: not checking m_compFactor because this function
	// is used to determine if limits have changed, and we
	// are not sending comp info to the client, therefore,
	// we do not want to trigger a message saying the limits
	// have changed

	if (
		(m_minPassSet		== limits.m_minPassSet) &&
		(m_maxPassSet		== limits.m_maxPassSet) &&
		(m_minOddsSet		== limits.m_minOddsSet) &&
		(m_maxOddsSet		== limits.m_maxOddsSet) &&
		(m_minPlaceSet		== limits.m_minPlaceSet) &&
		(m_maxPlaceSet		== limits.m_maxPlaceSet) &&
		(m_minHardPropsSet	== limits.m_minHardPropsSet) &&
		(m_maxHardPropsSet	== limits.m_maxHardPropsSet) &&
		(m_minFieldBigSet	== limits.m_minFieldBigSet) &&
		(m_maxFieldBigSet	== limits.m_maxFieldBigSet) &&

		(m_minTable			== limits.m_minTable) &&
		(m_maxTable			== limits.m_maxTable) &&
		(m_betOdds			== limits.m_betOdds) &&
		(m_field12Odds		== limits.m_field12Odds)
	   )
	   	return true;
	else
		return false;

}

//
// end of file
//
